package class_wuziqi;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

public class ChessBoard extends JPanel{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Image blackChess;
	private Image whiteChess;
	public ChessBoard() {
		blackChess=new ImageIcon(getClass().getResource("/pic/blackChessman.png")).getImage();
		whiteChess=new ImageIcon(getClass().getResource("/pic/whiteChessman.png")).getImage();
	}
	
	@Override
	public void paint(Graphics g) {
		Graphics2D g1=(Graphics2D)g;
		drawPanel(g1);
		 
	}

	private void drawPanel(Graphics2D g1) {
		Composite composite = g1.getComposite();//备份合成规则，可以使用更多功能
		Color color=g1.getColor();
		g1.setComposite(AlphaComposite.SrcOver.derive(0.9f));//设置透明合成
		g1.setColor(new Color(0xFAA755));
		g1.fill3DRect(0, 0, getWidth(), getHeight(), true);
		g1.setComposite(composite);
		g1.setColor(color);
		int width=getWidth();int height=getHeight();
		int chessW=width/15;int chessH=height/15;//设置棋子宽和高，棋子宽高等于棋格宽高
		int leftFra=chessW/2+width%15/2;//设置棋盘左边界
		int topFra=chessH/2+height%15/2;//设置棋盘上边界
		for(int i=0;i<15;i++){
			g1.drawLine(leftFra, topFra+chessH*i, leftFra+chessW*14, topFra+chessH*i);
			g1.drawLine(leftFra+chessW*i, topFra, leftFra+chessW*i, topFra+chessH*14);
		}
		Color chessArray[][]=new Color[15][15];
		chessArray[2][2]=color.white;
		for(int i=0;i<15;i++){
			for(int j=0;j<15;j++){
				if(chessArray[i][j]==color.white){
					g1.drawImage(whiteChess, (leftFra+chessW*i)-chessW/2, (topFra+chessH*j)-chessH/2, chessW, chessH, this);
				}
				else if(chessArray[i][j]==color.black){
					
				}
			}
		}
	}
}
